/***************************************************************************

Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

***************************************************************************/

using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.Package;
using Babel.Parser;
using Microsoft.VisualStudio.TextManager.Interop;
using dragonangel.phpProject.Language.DSL.Parser;

namespace Babel
{
    public static partial class Configuration
    {
        public const string Name = "PhpFile";
        public const string Extension = ".php";

        static CommentInfo myCInfo;
        public static CommentInfo MyCommentInfo { get { return myCInfo; } }

        public static string GetText(this IVsTextView view, int line, int col)
        {
            string text;
            view.GetTextStream(line, 0, line, col, out text);
            return text;
        }

        static Configuration()
        {
            myCInfo.BlockEnd = "*/";
            myCInfo.BlockStart = "/*";
            myCInfo.LineStart = "??";
            myCInfo.UseLineComments = false;

            // default colors - currently, these need to be declared
            CreateColor("Keyword", COLORINDEX.CI_BLUE, COLORINDEX.CI_USERTEXT_BK, false, false);
            CreateColor("Comment", COLORINDEX.CI_DARKGREEN, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Identifier", COLORINDEX.CI_AQUAMARINE, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("String", COLORINDEX.CI_RED, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Number", COLORINDEX.CI_SYSPLAINTEXT_FG, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Text", COLORINDEX.CI_SYSPLAINTEXT_FG, COLORINDEX.CI_USERTEXT_BK);

            TokenColor phpCode = CreateColor("phpCode", COLORINDEX.CI_RED, COLORINDEX.CI_USERTEXT_BK);
            TokenColor variableColor = CreateColor("Variable", COLORINDEX.CI_DARKBLUE, COLORINDEX.CI_USERTEXT_BK, true, false);
            TokenColor simpleString = CreateColor("StringSimple", COLORINDEX.CI_MAROON, COLORINDEX.CI_USERTEXT_BK);
            TokenColor brace = CreateColor("Brace", COLORINDEX.CI_DARKGRAY, COLORINDEX.CI_USERTEXT_BK);

            TokenColor error = CreateColor("Error", COLORINDEX.CI_RED, COLORINDEX.CI_USERTEXT_BK, false, true);

            //
            // map tokens to color classes
            //
            ColorToken((int)Tokens.BEGIN_CODE, TokenType.Operator, phpCode, TokenTriggers.None);
            ColorToken((int)Tokens.ALTERNATE_BEGIN_CODE, TokenType.Operator, phpCode, TokenTriggers.None);
            ColorToken((int)Tokens.END_CODE, TokenType.Operator, phpCode, TokenTriggers.None);

            ColorToken((int)Tokens.KWCLASS, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWINTERFACE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.TYPEIDENTIFIER, TokenType.Identifier, TokenColor.Identifier, TokenTriggers.None);
            ColorToken((int)Tokens.TYPEREFERENCEIDENTIFIER, TokenType.Identifier, TokenColor.Identifier, TokenTriggers.MemberSelect);
            ColorToken((int)Tokens.KWFUNCTION, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWPUBLIC, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWPRIVATE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWPROTECTED, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWPARENT, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);

            ColorToken((int)Tokens.KWINSTANCEOF, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWTHROW, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWNEW, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWIF, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWELSE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWELSEIF, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWWHILE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWFOR, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWCONTINUE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWBREAK, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWRETURN, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWINT, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWVOID, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWSTATIC, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWINT, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWGLOBAL, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWINCLUDE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWINCLUDEONCE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWREQUIRE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.KWREQUIREONCE, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.NUMBER, TokenType.Literal, TokenColor.Number, TokenTriggers.None);
            ColorToken((int)Tokens.KWFUNCTION, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.BUILTIN_FUNCTION, TokenType.Keyword, TokenColor.Keyword, TokenTriggers.None);
            ColorToken((int)Tokens.QUOTE, TokenType.String, TokenColor.String, TokenTriggers.None);
            ColorToken((int)Tokens.SIMPLEQUOTE, TokenType.String, simpleString, TokenTriggers.None);
            ColorToken((int)Tokens.QUOTESTRING, TokenType.Text, TokenColor.String, TokenTriggers.None);
            ColorToken((int)Tokens.SIMPLEQUOTESTRING, TokenType.Text, simpleString, TokenTriggers.None);

            ColorToken((int)Tokens.KWTHIS, TokenType.Keyword, variableColor, TokenTriggers.None);
            ColorToken((int)Tokens.VARIABLE, TokenType.Identifier, variableColor, TokenTriggers.None);

            ColorToken((int)Tokens.ACCESSOR, TokenType.Operator, TokenColor.Text, TokenTriggers.MemberSelect);

            ColorToken((int)'(', TokenType.Delimiter, brace, TokenTriggers.MatchBraces | TokenTriggers.ParameterStart);
            ColorToken((int)')', TokenType.Delimiter, brace, TokenTriggers.MatchBraces | TokenTriggers.ParameterEnd);
            ColorToken((int)',', TokenType.Delimiter, TokenColor.Text, TokenTriggers.ParameterNext);
            ColorToken((int)'{', TokenType.Delimiter, brace, TokenTriggers.MatchBraces);
            ColorToken((int)'}', TokenType.Delimiter, brace, TokenTriggers.MatchBraces);

            //// Extra token values internal to the scanner
            ColorToken((int)Tokens.LEX_ERROR, TokenType.Text, error, TokenTriggers.None);
            ColorToken((int)Tokens.LEX_COMMENT, TokenType.Comment, TokenColor.Comment, TokenTriggers.None);
            ColorToken((int)Tokens.LEX_WHITE, TokenType.WhiteSpace, TokenColor.Text, TokenTriggers.None);
        }
    }
}